﻿Public Class frmCargaNombres

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ToExcel(dgNombres, "Nombres")
    End Sub

    Private Sub btnExaminar_Click(sender As System.Object, e As System.EventArgs) Handles btnExaminar.Click
        Dim oFD As New OpenFileDialog
        With oFD
            .Title = "Seleccionar fichero"
            .Filter = "Ficheros de texto (*.xls;*.xlsx)|*.xls;*.xlsx" & _
                      "|Todos los ficheros (*.*)|*.*"
            .FileName = Me.txtFichero.Text
            If .ShowDialog = System.Windows.Forms.DialogResult.OK Then
                Me.txtFichero.Text = .FileName
            End If
        End With
        Excel()
    End Sub
    Private Sub Excel()
        Dim xl As Object
        Dim wb As Object

        'Crear objeto excel
        xl = CreateObject("Excel.Application")
        xl.Visible = False
        wb = xl.activeworkbook
        wb = xl.Workbooks.Open(txtFichero.Text)

        Dim rng As Integer = 5
        Dim col As Integer = 2
        Dim i As Integer = 5
        Dim cont As Integer = 0

        Dim IdEmpleado As String = ""
        Dim Lic As New clsLicencia

        For i = 3 To 1000
            IdEmpleado = wb.sheets(2).cells(i, 1).value
            If IdEmpleado = "" Then
                Exit For
            End If
            Lic.idempleado = wb.sheets(2).cells(i, 1).value
            Lic.Licencia = wb.sheets(2).cells(i, 44).value
            Lic.Tipo = "B"
            Lic.Vigencia = CDate(wb.sheets(2).cells(i, 45).value)
            Lic.Insertar()
        Next

        'cerramos el archivo Excel
        wb.CLOSE(False)
        xl.quit()
        xl = Nothing

        frmModuloEmpleados.CargaEmpleados()
        Application.DoEvents()
        Close()
    End Sub
End Class